#include <stdio.h>
#include <stdlib.h>

struct BoundedIntStack
{
    size_t len;
    size_t size;
    int* ary;
};

/*
 * creates bounded int stack
 *
 * @name bis_create
 * @arg 0 struct BoundedIntStack*
 * @arg 1 size_t
 *
 * @pre NULL != #arg0
 * @pre #arg1 > 0
 *
 * @post NULL != #arg0->ary
 */
void bis_create (struct BoundedIntStack* bis, size_t size)
{
    bis->size = size;
    bis->len = 0;
    bis->ary = malloc (size * sizeof (int));
}

/*
 * Destroy bounded int stack
 *
 * @name bis_destroy
 * @arg 0 struct BoundedIntStack*
 *
 * @pre NULL != #arg0
 * @pre NULL != #arg0->ary
 *
 * @post NULL == #arg0->ary
 */
void bis_destroy (struct BoundedIntStack* bis)
{
    free (bis->ary);
    bis->ary = NULL;
}

/*
 * returns top of bounded stack
 *
 * @name bis_push
 * @arg  0 struct BoundedIntStack*
 *
 * @pre NULL != #arg0
 * @pre NULL != #arg0->ary
 * @pre #arg0->len <= #arg0->size
 * @pre #arg0->len > 0
 */
int bis_top (struct BoundedIntStack* bis)
{
    return bis->ary[bis->len - 1];
}

/*
 * pushes element onto bounded int stack
 *
 * @name bis_push
 * @arg  0 struct BoundedIntStack*
 *
 * @pre NULL != #arg0
 * @pre NULL != #arg0->ary
 * @pre #arg0->len < #arg0->size
 *
 * @post #arg0->len > 0
 * @post bis_top (#arg0) == #arg1
 */
void bis_push (struct BoundedIntStack* bis, int i)
{
    bis->ary[bis->len++] = i;
}

/*
 * pops element from bounded int stack
 *
 * @name bis_pop
 * @arg  0 struct BoundedIntStack*
 *
 * @pre NULL != #arg0
 * @pre NULL != #arg0->ary
 * @pre #arg0->len > 0
 */
void bis_pop (struct BoundedIntStack* bis)
{
    --bis->len;
}

int main (const int argc, char const* argv[])
{
    struct BoundedIntStack bis;

    bis_create (&bis, 5);
    bis_push (&bis, 1);
    bis_push (&bis, 2);
    bis_push (&bis, 3);
    bis_push (&bis, 4);
    bis_push (&bis, 5);
    bis_top (&bis);
    bis_pop (&bis);
    bis_pop (&bis);
    bis_top (&bis);
    bis_push (&bis, 6);
    bis_destroy (&bis);

    return 0;
}

